﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 线程相关学习
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 线程5秒后强制停止
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            System.Threading.Semaphore aaa = new System.Threading.Semaphore(2, 5);

            System.Threading.CountdownEvent evt = new System.Threading.CountdownEvent(10);
            //evt.
            System.Threading.SemaphoreSlim bbb = new System.Threading.SemaphoreSlim(50);
            System.Threading.Thread thr = new System.Threading.Thread(() => {

               
                System.Threading.Thread.Sleep(500);
                Console.Write("已经停止");
            });
            thr.Start();
            bbb.Wait(50);
            bbb.Release();
        }
    }
}
